import axios from 'axios'
import { getToken } from '../../helpers/token'

axios.defaults.headers.Authorization = `Bearer ${getToken()}`

/**
 * 新增商品请求
 *
 * @param {Object} addForm 新增商品表单数据
 */
export const addGood = addForm =>
  axios.post('http://localhost:3000/good/add', addForm)

/**
 * 获取商品列表
 *
 * @param {Number} page 页码
 * @param {Number} size 每页条数
 */
export const getGoodlist = (page, size, keyword) =>
  axios.get('http://localhost:3000/good/list', {
    params: {
      page,
      size,
      keyword
    }
  })

/**
 * 删除商品请求
 *
 * @param {String} goodId 商品id
 */
export const delGood = goodId =>
  axios.delete(`http://localhost:3000/good/${goodId}`)

/**
 * 出库入库请求
 *
 * @param {String} goodId 商品id
 * @param {String} type 出入库类型
 * @param {Number} num 出入库数量
 */
export const updateCount = (goodId, type, num) =>
  axios.post('http://localhost:3000/good/count', {
    id: goodId,
    type,
    num
  })

/**
 * 更新商品信息接口
 *
 * @param {Object} editForm 修改后商品信息
 */
export const updateGood = editForm =>
  axios.post('http://localhost:3000/good/update', editForm)

/**
 * 商品详情接口
 *
 * @param {String} goodId 商品id
 */
export const getDetail = goodId =>
  axios.get(`http://localhost:3000/good/detail/${goodId}`)
